// components/evaluate/evaluate.js
//获取应用实例
const app = getApp()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    //小程序页面的表头
    productId: {
      type: Number,
      default: 0
    },
    pageSize: {
      type: Number,
      default: 1
    }, 
  },

  /**
   * 组件的初始数据
   */
  data: {
    productLists:[],
    page:1,
    totals:0,
  },
  ready(config){
    this.getProductView();
  },
  /**
   * 组件的方法列表
   */
  methods: {
    getProductView(){ // 获取商品评价列表
      let that=this;
      wx.request({
        url: app.globalData.urls + '/product/review?product_id=' + this.data.productId + '&page=1&page_size=' + this.data.pageSize,
        header: app.getRequestHeader(),
        data: {},
        success: function (res) {
          if (res.data.code == 200) {
            let getdata =  res.data.data;
            that.setData({
              productLists: getdata.list,
              totals: Number(getdata.totalCount)
            })
            that.triggerEvent('totalViews', getdata.totalCount) 
            app.saveReponseHeader(res);
          }
        }
      })
    },

    loadProduct: function (e) {
      if (this.data.page < this.data.totals){
        this.setData({
          page: this.data.page+1,
        });
        this.getProductView();
      }
      console.log("eeeeee", e, this.data.totals)
    },

    preview(e){
      wx.previewImage({
        current: e.currentTarget.dataset.src, // 当前显示图片的http链接
        urls: e.currentTarget.dataset.srcs // 需要预览的图片http链接列表
      })
    }
  }
})
